<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>表单组合</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/extends/AmazeUI-2.7.2/css/amazeui.css">
    <link href="__STATIC__/css/base.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/style/admin.css" media="all">

    <script src="__STATIC__/js/jquery-1.8.3.min.js"></script>
    <script src="__STATIC__/extends/AmazeUI-2.7.2/js/amazeui.min.js"></script>

    <link rel="stylesheet" href="__STATIC__/css/seller.css">
    <link rel="stylesheet" href="__STATIC__/css/seller_goods.css">
    <script src="__STATIC__/js/common1.js"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">{$type}</div>
        <div class="layui-card-body" style="padding: 15px;">
            {if $info}
            <form method="post" action="{:url('editPost')}" class="layui-form">
            <input type="hidden" name="id" value="{$info.id}"/>
            {else /}
            <form method="post" action="{:url('addPost')}" class="layui-form">

            {/if}

                    <div style="margin-top: 2%"></div>

                    <div class="layui-inline">
                        <label class="layui-form-label">所属系统分类：</label>
                        <div class="layui-input-inline">
                            <select name="systemid"  lay-verify="required" lay-filter="down_link_name" id="down_link_name">
                                <option  value="0">请选择商品分类</option>
                                {volist name="goodscate" id="vo"}
                                <option {if $goodscurl[1] == $vo.gcate_id}selected{/if}  value="goods_{$vo['gcate_id']}">{$vo.goodscatename|raw}</option>
                                {/volist}

                                <option value="0" disabled>——————————————</option>
                                
                                <option  value="0">请选择文章分类</option>
                                {volist name="articate" id="voart"}
                                <option {if $goodscurl[1] == $voart.art_id}selected{/if} value="article_{$voart['art_id']}">{$voart.artname|raw}
                                </option>
                                {/volist}

                                <option value="0" disabled>——————————————</option>

                                <option  value="0">请选择单页分类</option>
                                {volist name="pagecate" id="vopage"}
                                <option  {if $goodscurl[1] == $vopage.page_id}selected{/if} value="page_{$vopage['page_id']}">{$vopage.pagename|raw}
                                </option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    <div style="margin-top: 2%"></div>
                        <div class="layui-inline">
                            <label class="layui-form-label">所属导航上级分类：</label>
                            <div class="layui-input-inline">
                                <select name="parentid"  lay-verify="required" >
                                    <option  value="0">请选所属导航上级</option>
                                    {volist name="category" id="vo"}
                                    <option {if $info['parentid'] == $vo.id}selected{/if}  value="{$vo['id']}">{$vo.lcatname|raw}</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>
                    <div style="margin-top: 2%"></div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">导航名称：</label>
                        <div class="layui-input-block formControls">
                            <input type="text" lay-verify="title" autocomplete="off" placeholder="导航名称不能为空" value="{$info.categoryname}"  name="categoryname" {if empty($info)} datatype="*" nullmsg="导航名称不能为空！" ajaxurl="{:url('category/ajaxCate')}" {else/} datatype="*" nullmsg="导航名称不能为空！" ajaxurl="{:url('category/ajaxCate',array('id'=>$info['id']))}" {/if} class="layui-input">
                            <span class="Validform_checktip"></span>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">导航关键词：</label>
                        <div class="layui-input-block formControls">
                            <input type="text" lay-verify="title" autocomplete="off" placeholder="导航关键词不能为空"  name="keywords" value="{$info.keywords}"  class="layui-input">
                            <span class="Validform_checktip"></span>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">导航描述：</label>
                        <div class="layui-input-block">
                            <textarea type="text" lay-verify="description" class="layui-textarea" autocomplete="off" placeholder="导航描述不能为空"  name="description" >{$info['description']}</textarea>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">导航位置:</label>
                        <div class="layui-input-block">

                            <input type="radio" name="position" value="0" title="上" {$info.position?'':'checked'}>
                            <input type="radio" name="position" value="1" title="下" {$info.position?'checked':''}>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">新窗口打开:</label>
                        <div class="layui-input-block">
                            <input type="radio" name="is_blank" value="1" title="是" {$info.is_blank?'checked':''}>
                            <input type="radio" name="is_blank" value="0" title="否" {$info.is_blank?'':'checked'}>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">系统链接:</label>
                        <div class="layui-input-block formControls">
                            <input type="text" lay-verify="title" autocomplete="off" id="hezi" name="url" value="{$info['url']}" class="layui-input">
                            <span class="Validform_checktip"></span>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">是否显示:</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="1" title="显示" {$info.status?'checked':''}>
                            <input type="radio" name="status" value="0" title="隐藏" {$info.status?'':'checked'}>
                        </div>
                    </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">排序:</label>
                    <div class="layui-input-block formControls">
                        <input type="text" lay-verify="title" autocomplete="off"  name="sort" {if empty($info)} value="50" {else/}value="{$info['sort']}" {/if} class="layui-input">
                        <span class="Validform_checktip"></span>
                    </div>
                </div>

                    <div class="layui-form-item layui-layout-admin">
                        <div class="layui-input-block">
                            <div class="layui-footer" style="left: 0;">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-demo1">立即提交</button>
                                <a href="{:url('Category/index')}" class="layui-btn layui-btn-primary">返回</a>
                            </div>
                        </div>
                    </div>
                </form>
        </div>
    </div>
</div>

<script src="__STATIC__/extends/layui2.4.5/layui.all.js "></script>
<script src="__STATIC__/extends/Validform/5.3.2/Validform.min.js "></script>
<script src="__STATIC__/extends/js/jquery-ui.js"></script>
<script src="__STATIC__/js/seller_goods.js"></script>
<script src="__STATIC__/js/seller_goods_sku.js"></script>

<script type="text/javascript">
    $(function() {
        //表单验证
        $("form").Validform({
            tiptype:function(msg,o,cssctl){
                if(!o.obj.is("form")){
                    //默认表单
                    var objtip=o.obj.parents(".formControls").find(".Validform_checktip");
                    cssctl(objtip,o.type);
                    objtip.text(msg);
                }
            },
            showAllError:true
        })

    });
</script>

<script src="__STATIC__/layuiadmin/layui/layui.js"></script>

<script>
    layui.config({
        base: '__STATIC__/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'laydate'], function(){
        var $ = layui.$
            ,admin = layui.admin
            ,element = layui.element
            ,layer = layui.layer
            ,laydate = layui.laydate
            ,form = layui.form;

        form.render('checkbox');
        form.render(null, 'component-form-group');

        laydate.render({
            elem: '#LAY-component-form-group-date'
        });
        return false;
    });


    layui.use(['form', 'upload'], function () {
        var upload = layui.upload;
        upload_img('image');
        function upload_img (id) {
            //选完文件后自动上传
            upload.render({
                elem: '#'+id,
                url: "{:url('UpFiles/upload')}",
                auto: true,
                accept: 'file', //普通文件
                data :{type:id,name:'file'},
                before: function (obj) {
                    var img_url = $('input[name='+id+']').val();
                    // 删除老数据
                    if (img_url != '') {
                        $.ajax({
                            url: "{:url('UpFiles/delImg')}",
                            type: 'POST',
                            data: {
                                img_url: img_url
                            },
                        });
                    }
                    //本地本地预览示例
                    obj.preview(function(index,file,result){
                        $("#"+id+"_thumb").attr('src',result).show();
                    });
                },
                done: function (res) {
                    //上传完毕回调
                    if (res.code > 0) {
                        return layer.msg('上传失败');
                    } else {
                        $("#"+id+"_thumb").attr('src',res.data.src).show();
                        $('input[name='+id+']').val(res.data.src);
                    }
                }
            });
        }
    });

    layui.use('form',function(){
        var form = layui.form,$ = layui.jquery;
        form.on('select(down_link_name)', function (data) {
            var type = data.value;
            var url =  "{:url('CateAddPost')}?isajax="+type;
            field_setting(type,url,form);
        })

    });


    //选择后变更
    function field_setting(type,url,form){
        $.ajax({
            type: "POST",
            url: url,
            data: '',
            beforeSend:function(){
                $('#field_setup').html('<i class="fa fa-spinner fa-spin fa-fw"></i>');
            },
            success: function(msg){
                //alert(msg);
                $(this).val("");
                console.info(msg);
                $('#hezi').val(msg.msg);

                form.render();
            }
        });
    }
</script>
</body>
</html>
